﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Survey.Models.Where
{
    public class AdminWhereModel : IEFWhere<Admin>
    {
        public long? Id { get; set; }
        public string? Account { get; set; }
        public string? TrueName { get; set; }
        public string? OpenId { get; set; }
        public string? Phone { get; set; }
        public long? RoleId { get; set; }
        public int? LockState { get; set; }
        public int? Page { get; set; }
        public int? Limit { get; set; }
        public IQueryable<Admin> Process(IQueryable<Admin> query, out int count)
        {
            if (Id.HasValue && Id.Value > 0)
            {
                query = query.Where(x => x.Id == Id.Value);
            }
            if (RoleId.HasValue && RoleId.Value > 0)
            {
                query = query.Where(x => x.RoleId == RoleId.Value);
            }
            if (LockState.HasValue && LockState.Value > 0)
            {
                query = query.Where(x => x.LockState == LockState.Value);
            }
            if (!string.IsNullOrEmpty(Account))
            {
                query = query.Where(x => x.Account == Account);
            }
            if (!string.IsNullOrEmpty(Phone))
            {
                query = query.Where(x => x.Phone == Phone);
            }
            if (!string.IsNullOrEmpty(TrueName))
            {
                query = query.Where(x => x.TrueName != null && x.TrueName.Contains(TrueName));
            }
            count = query.Count();
            if (Limit.HasValue && Page.HasValue && Limit.Value > 0 && Page.Value > 0)
            {
                query = query.Skip((Page.Value - 1) * Limit.Value).Take(Limit.Value);
            }
            return query;
        }
    }
}
